﻿/*----------------------------------------------------------------
// Copyright (C) 2013 上海汽车集团股份有限公司
// 版权所有。
//
// 文件名：Common.js
// 文件功能描述：公共函数文件
//              文件依赖： 
//                       jquery-1.8.0.min.js、
//                       Window.js  
//                       
//
//
// 创建标识：  曹珊 2013/8/16
//
// 修改标识：
// 修改描述：
// 
//----------------------------------------------------------------*/
//Ajax
(function ($) {
    jQuery.pubAjax = function (settings) {
        if (settings.url != "" && settings.url != null) {
            settings.url = GetRandURL(settings.url);
            settings = jQuery.extend({
                errorHandle: true, //是否处理服务器错误 error.call
                errorMessageAlertCallBack: function () { },
                type: "post",
                contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                data: settings.data,
                datatype: 'json',
                async: false, //同步
                cache: false,
                statusCode: {
                    404: function () { jqAlert('无效的URL'); }
                },
                beforeSend: function (xmlHttpRequest) {
                    this;
                },
                complete: function (xmlHttpRequest, status) {
                    this;
                },
                success: function (data) {
                    this;
                },
                error: function (xmlHttpRequest, status, errorThrown) {
                    this;
                },
                ajaxError: function () { }
            }, settings);
        } else {
            jqAlert('请指定URL');
            return;
        }

        var btnObj = null;
        var currentWindow = null;

        if (!isNullOrEmpty(settings.buttonEvent)) {
            //ie and firefox
            if ($.browser.msie || $.browser.mozilla) btnObj = $(settings.buttonEvent.target);
            //chrome
            else btnObj = $(settings.buttonEvent.currentTarget);
        }

        if (!isNullOrEmpty(settings.currentWindow)) {
            currentWindow = settings.currentWindow;
        }

        jQuery.ajax({
            type: settings.type,
            url: settings.url,
            cache: settings.cache,
            sync: settings.async,
            contentType: settings.contentType,
            data: settings.data,
            datatype: settings.datatype,
            statusCode: settings.statusCode,
            success: function (data) {
                var result = eval('(' + data + ')');
                ajaxSuccess(result, settings.success, settings.errorMessageAlertCallBack);
            },
            error: function (xmlHttpRequest, status, errorThrown) {
                if (settings.errorHandle) {
                    var strErrMsg = "意外出错，请刷新页面重试!";
                    jqAlert(strErrMsg, function () {
                        settings.error(xmlHttpRequest, status, errorThrown);
                    });
                } else {
                    ;
                }

                if (null != btnObj) btnObj.button('enable'); //启用按钮 
                if (null != currentWindow) {
                    UnLockWindow(currentWindow); //解锁窗口
                    HidePrompt(currentWindow);
                }
            },
            beforeSend: function (xmlHttpRequest) {
                settings.beforeSend(xmlHttpRequest);

                if (null != btnObj) btnObj.button('disable'); //禁用按钮 
                if (null != currentWindow) {
                    LockWindow(currentWindow); //锁定窗口
                    ShowPrompt(currentWindow);
                }
            },
            complete: function (xmlHttpRequest, status) {
                settings.complete(xmlHttpRequest, status);

                if (null != btnObj) btnObj.button('enable'); //启用按钮 
                if (null != currentWindow) {
                    UnLockWindow(currentWindow); //解锁窗口
                    HidePrompt(currentWindow);
                }
            }
        });
    }
})(jQuery);

//双斜杠转换为单斜杠
function ConvertSlash(changeValue) {
    return changeValue.replace("//", "/");
}

function ignoreSpaces(string) {
    var temp = "";
    string = '' + string;
    var splitstring = string.split(" ");
    for (var i = 0; i < splitstring.length; i++) {
        temp += splitstring[i];
    }
    return temp;
}

//获取随机数
function GetRandomNum(Min, Max) {
    var Range = Max - Min;
    var Rand = Math.random();
    return (Min + Math.round(Rand * Range));
}
//URL 参数赋值
function setUrlParam(oldurl, paramname, pvalue) {
    var reg = new RegExp("(\\?|&)" + paramname + "=([^&]*)(&|$)", "gi");
    var pst = oldurl.match(reg);
    if ((pst == undefined) || (pst == null)) {
        return oldurl + ((oldurl.indexOf("?") == -1) ? "?" : "&") + paramname + "=" + pvalue;
    }

    var t = pst[0];
    var retxt = t.substring(0, t.indexOf("=") + 1) + pvalue;
    if (t.charAt(t.length - 1) == '&') retxt += "&";

    return oldurl.replace(reg, retxt);
}

//获取Radion选中的值
function GetRadioCheckedValue(strName) {
    return $("input[name='" + strName + "'][checked]").val()
}

//获取通过name获取input的value值
function GetInputValue(strName) {
    return $.trim($("input[name='" + strName + "']").val());
}

//获取通过name获取input的value值
function GetCheckboxValue(strName) {
    var str = "";
    $("input[name='" + strName + "']:checkbox").each(function () {
        if ($(this).attr("checked")) {
            str += $(this).val() + ","
        }
    })
    return str
}

//URL增加随机数,防止页面缓存
function GetRandURL(url) {
    url = setUrlParam(url, "rannum", GetRandomNum(0, 99999999));
    return url;
}

//将Form中的输入值URL序列化，各值之间用&分割。
function getRequestBody(oForm) {
    var aParams = new Array();
    for (var i = 0; i < oForm.elements.length; i++) {
        if (oForm.elements[i].name != '__VIEWSTATE') {
            if (oForm.elements[i].id != "") {
                var sParam = oForm.elements[i].id;

                if (oForm.elements[i].type == "checkbox" || oForm.elements[i].type == "radio") {
                    if (oForm.elements[i].checked) {
                        sParam += "=";
                        sParam += encodeURIComponent(oForm.elements[i].value);
                        aParams.push(sParam);
                    }
                }
                else {
                    sParam += "=";
                    sParam += encodeURIComponent(oForm.elements[i].value);
                    aParams.push(sParam);
                }
            }
        }
    }

    return aParams.join("&");
}

//获取POST页面参数
function getPostBody(formID) {
    var vForm = document.forms[0];
    if (typeof (formID) != "undefined") {
        vForm = document.getElementById(formID);
    }
    var vPostData = getRequestBody(vForm);
    return vPostData;
}

//获取POST页面参数
function getPostData(formID) {
    var vPostData = getPostBodyToJson(formID);
    return vPostData;
}

//获取POST页面参数组合成Json数据
function getPostBodyToJson(formID) {
    var vForm = document.forms[0];
    if (typeof (formID) != "undefined") {
        vForm = document.getElementById(formID);
    }
    var vPostData = getRequestToJson(vForm);
    return vPostData;
}

//通过Form name组合Json数据
function getRequestToJson(oForm) {
    var aParams = new Object();
    var message = "";
    for (var i = 0; i < oForm.elements.length; i++) {

        if (oForm.elements[i].name != '__VIEWSTATE' && oForm.elements[i].name != '__EVENTVALIDATION') {
            if (oForm.elements[i].id != "") //没有ID的不生成串
            {
                var data;
                if ($(oForm.elements[i]).hasClass("easyui-combobox")) {
                    var selectValue = "";
                    data = $('#' + oForm.elements[i].id).combobox('getData');
                    selectValue = $('#' + oForm.elements[i].id).combobox('getValue').Trim();
                    var find = false;
                    for (var j = 0; j < data.length; j++) {

                        if (data[j].ID != undefined) {
                            if (selectValue.toString() == data[j].ID.Trim()) {
                                find = true;
                                break;
                            }
                        }
                        if (data[j].Text != undefined) {
                            if (selectValue.toString() == data[j].Text.Trim()) {
                                find = true;
                                break;
                            }
                        }
                        if (data[j].value != undefined) {
                            if (selectValue.toString() == data[j].value.Trim()) {
                                find = true;
                                break;
                            }
                        }
                        if (data[j].text != undefined) {
                            if (selectValue.toString() == data[j].text.Trim()) {
                                find = true;
                                break;
                            }
                        }
                    }
                    if (data.length == 0) {
                        if (selectValue == "") {
                            find = true;
                        }
                    }
                    if (!find) {
                        message += selectValue + ",";
                    }
                    aParams[oForm.elements[i].id] = selectValue;
                }
                else if ($(oForm.elements[i]).hasClass("____HIDGRIDDATA")) {
                    var gridID = $(oForm.elements[i]).attr("GridID");
                    if ("" != gridID) {
                        data = $("#" + gridID).jqGrid('getRowData');
                        var cols = $(oForm.elements[i]).attr('RDModel');
                        var colsArr = cols.split(',');

                        var temp = [];
                        for (var k = 0; k < data.length; k++) {
                            var json = {};
                            for (var j = 0; j < colsArr.length; j++) {
                                var v = data[k][colsArr[j]];
                                if (isNullOrEmpty(v)) {
                                    v = "";
                                }
                                json[colsArr[j]] = v;
                            }
                            temp.push(json);
                        }
                        if (temp.length > 0) {
                            aParams[oForm.elements[i].id] = temp.Serialize();
                        }
                    }
                }
                else if ($(oForm.elements[i]).attr('type') == "checkbox") {
                    aParams[oForm.elements[i].id] = $(oForm.elements[i]).attr('checked') == "checked" ? 1 : 0;
                }
                else {
                    aParams[oForm.elements[i].id] = encodeURIComponent(escape(oForm.elements[i].value.Trim()));
                }
            }
        }
    }

    if (message.length != 0) {
        message = message.substring(0, message.length - 1);
        jqAlert("下拉框中不存在以下数据：<br />" + message + "<br />请修改！");
        return "nodata";
    }

    return aParams;
}

function ClearForm(formID) {
    $("#" + formID).find('input,select,textarea').each(function (i, item) {
        //$("#" + FormID + " input,select,textarea").each(function (i, item) {
        if ($(item).attr('type') == 'hidden') {
            $(item).val('');
        }
        if ($(item).hasClass("easyui-combobox")) {
            //$(item).combobox('options').onSelect = function () { };
            if ($(item).attr('cascade')) {
                $(item).combobox('options').onSelect = function () { };
                $(item).combobox("clear");
                $(item).combobox("loadData", []);
            } else {
                var isDivision = $(item).data("isDivision");
                if (isDivision) {
                    $(item).combobox('options').onSelect = function () { };
                    $(item).combobox('select', $(item).data("DefaultDivision"));
                }
                else {
                    $(item).combobox('select', "");
                }
            }
        }
        if ($(item).hasClass('easyui-combotree')) {
            $(item).combotree("clear");
        }
        if ($(item).hasClass("TextBox")) {
            $(item).val('');
        }
        if ($(item).hasClass("TextArea")) {
            $(item).val('');
        }
    });
}

function search_more() {
    if ($('#button4').hasClass("btn_down")) {
        $('#button4').removeClass("btn_down").addClass("btn_up");
    } else {
        $("#button4").removeClass("btn_up").addClass("btn_down");
    }
    $(".inputbox").toggle();
    $(window).resize();
}

//提交表单，执行easyui验证
function submitJSONForm(url, htmlFormId, callback, btnEvent, currentWindow, onFailCallBack) {

    if (!EasyUiValidate(htmlFormId)) {
        return false;
    }

    var vPostData = getPostBodyToJson(htmlFormId);
    if ($.type(vPostData) == "string") {
        if (vPostData == "nodata")
            return false;
    }

    url = GetRandURL(url);
    $.pubAjax({
        url: url,
        data: vPostData,
        type: "POST",
        currentWindow: currentWindow,
        buttonEvent: btnEvent,
        errorMessageAlertCallBack: onFailCallBack,
        success: function (data) {
            callback(data);
        },
        error: function (xmlHttpRequest, status, errorThrown) {
        },
        complete: function (xmlHttpRequest, status) {
        }
    });
}

function toggle_div(btId, divID) {
    if ($("#" + btId).hasClass("btn_down")) {
        $("#" + btId).removeClass("btn_down").addClass("btn_up");
    } else {
        $("#" + btId).removeClass("btn_up").addClass("btn_down");
    }
    $("#" + divID).toggle();
    $(window).resize();
}

function submitData(url, vPostData, callback, btnEvent, currentWindow, onFailCallBack) {
    var btnObj = null;
    if (!isNullOrEmpty(btnEvent)) {
        btnObj = $(btnEvent.target);
        btnObj.button('disable'); //禁用按钮
    }
    url = GetRandURL(url);
    $.pubAjax({
        url: url,
        data: vPostData,
        type: "POST",
        currentWindow: currentWindow,
        buttonEvent: btnEvent,
        errorMessageAlertCallBack: onFailCallBack,
        success: function (data) {
            callback(data);
        },
        error: function (XMLHttpRequest, Status, errorThrown) {
            if (null != btnObj) btnObj.button('enable'); //启用按钮 
        },
        complete: function (XMLHttpRequest, Status) {
            if (null != btnObj) btnObj.button('enable'); //启用按钮     
        }
    });
}

function ajaxSuccess(result, callback, jqAlertCallBack) {
    //登陆超时
    if (result.Status == 100) {
        jqAlert(BuildExceptionMessage(result), function () { location.href = "/login.aspx"; });
        return;
    }

    if (result.Status == 200) {
        //成功
        if (!isNullOrEmpty(callback)) {
            if (result === null) {
                callback(null);
                return;
            }
            var contentType = $.type(result.Content);
            if (contentType === "undefined" || contentType === "null") {
                callback(result);
            }
            else {
                callback(result.Content);
            }
        }
    }
    else if (result.Status == 300) {
        //失败
        var msg = result.StateDescription;
        if (jqAlertCallBack) {
            jqAlert(msg, jqAlertCallBack);
        }
        else {
            jqAlert(msg);
        }
    }
    else if (result.Status == 500) {
        //代码异常
        var title = "服务器错误：<br />日志ID：" + result.LogID + "<br />";
        var message = title + result.StateDescription;

        if (jqAlertCallBack) {
            jqAlert(message, jqAlertCallBack);
        }
        else {
            jqAlert(message);
        }
    }
    else if (result.Status == 600) {
        //平台异常
        var msg = BuildExceptionMessage(result);

        if (jqAlertCallBack) {
            jqAlert(msg, jqAlertCallBack);
        }
        else {
            jqAlert(msg);
        }
    }


}

function validateInt(value) {
    var r = /^[0-9]*[1-9][0-9]*$/;
    return r.test(value);
}

//easyui表单验证
function EasyUiValidate(formId) {
    var isValid = true;
    $("#" + formId).find('input,select,textarea,.easyui-combobox,.easyui-combotree').each(function () {
        if ($(this).attr('required') || $(this).attr('validType') || $(this).attr('data-options')) {
            if ($(this).hasClass('easyui-combobox')) {
                if (!$(this).combobox('isValid')) {
                    isValid = false;
                    return;
                }
            }
            if ($(this).hasClass('easyui-combotree')) {
                if (!$(this).combotree('isValid')) {
                    isValid = false;
                    return;
                }
            }
            if (!$(this).validatebox('isValid')) {
                isValid = false;
                return;
            }
        }
    });
    return isValid;
}


/**************验证**************/

//扩展验证
$.extend($.fn.validatebox.defaults.rules, {
    integer: {
        validator: function (value) {
            return /^-?\d+$/.test(value);
        },
        message: '该项应为整数'
    },
    NegativeABC:
    {
        validator: function (value) {
            return /^-?\d+$/.test(value);
        },
        message: '该项应为整数'
    },
    positiveInteger: {
        validator: function (value) {
            return /^[0-9]*[1-9][0-9]*$/.test(value);
        },
        message: '该项应为大于0的整数'
    },
    Negative: {
        validator: function (value) {
            return /^[0-9]*[0-9][0-9]*$/.test(value);
        },
        message: '该项应为非负整数'
    },
    decimal: {
        validator: function (value) {
            return /^(-?\d+)(\.\d+)?$/.test(value);
        },
        message: '该项应为数字'
    },
    ZIPCode: {
        validator: function (value) {
            return /^[1-9]\d{5}$/.test(value);
        },
        message: '邮政编码不存在'
    },
    AreaNum: {
        validator: function (value) {
            return /^\d{3,4}$/.test(value);
        },
        message: '区号不正确'
    },
    Tell: {
        validator: function (value) {
            return /^(\d{3,4}-)?\d{6,8}$/.test(value);
        },
        message: '电话号码格式不正确'
    },
    PHONENUMBER: {
        validator: function (value) {
            return /^[1]+[3,5,8]+\d{9}/.test(value);
        },
        message: '手机号码格式不正确'
    },
    extensionNumber: {
        validator: function (value) {
            return /^[0-9]*[1-9][0-9]*$/.test(value);
        },
        message: '分机号码格式不正确'
    },
    Fax: {
        validator: function (value) {
            return /^(\d{3,4}-)?\d{7,8}$/.test(value);
        },
        message: '传真号码格式不正确'
    },
    FaxextensionNumber: {
        validator: function (value) {
            return /^[0-9]*[1-9][0-9]*$/.test(value);
        },
        message: '传真分机号码格式不正确'
    },

    IncludeChinese: {
        validator: function (value) {
            return !/.*[\u4e00-\u9fa5]+.*$/.test(value);
        },
        message: '字符中不能包含中文'
    },

    MaxLength: {
        validator: function (value, parm) {
            return value.length <= parm[0];
        },
        message: '字符长度不能超过{0}位'
    },

    MinLength: {
        validator: function (value, parm) {
            return value.length >= parm[0];
        },
        message: '字符长度必须大于{0}位'
    },
    //combobox 必填
    ComboRequired: {
        validator: function (value, parm) {
            if (parm == undefined) {
                jqAlert('请指定 [ComboRequired] 验证参数。'); return;
            }
            if ($("#" + parm[0]).length == 0) {
                jqAlert('错误的 [ComboRequired] 验证参数。'); return;
            }
            var value = $("#" + parm[0]).combobox('getValue');
            if ("" == value)
                return false;
            var data = $("#" + parm[0]).combobox('getData');
            var find = false;
            for (var j = 0; j < data.length; j++) {
                if (value == data[j].ID || value == data[j].Text) {
                    find = true;
                    break;
                }
            }
            return find;
        },
        message: '必选项'
    },
    ComboTreeRequired: {
        validator: function (value, parm) {
            if (parm == undefined) {
                jqAlert('请指定 [ComboTreeRequired] 验证参数。'); return;
            }
            if ($("#" + parm[0]).length == 0) {
                jqAlert('错误的 [ComboTreeRequired] 验证参数。'); return;
            }
            if ($("#" + parm[0]).combotree('getValues') == '') {
                return false;
            }
            return true;
        },
        message: '必选项'
    },
    DecimelThree: {
        validator: function (value) {
            return /(^-?(?:(?:\d{0,3}(?:,\d{3})*)|\d*))(\.(\d{1,3}))?$/.test(value);
        },
        message: '大于0且小数不能超过3位'
    },
    DecimelTwo: {
        validator: function (value) {
            return /^[0-9]+(.[0-9]{2})?$/.test(value);
        },
        message: '非负数，如果是有小数部分，必须是2位小数'
    },
    TwoCharacter: {
        validator: function (value) {
            return /^[A-Za-z0-9]{2}/.test(value);
        },
        message: '必须为2位数字或者字符组合'
    },
    TellAndPhone: {
        validator: function (value) {
            return /(^(\d{3,4}-)?\d{7,8}$)|(^1[2|3|4|5|6|7|8|9][0-9]\d{4,8}$)/.test(value);
        },
        message: '电话或者手机格式不正确'//既可以是电话号码也可以是手机号码，7到11位
    },
    Email: {
        validator: function (value) {
            return /^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/.test(value);
        },
        message: '邮箱格式不正确'
    }
});

function ReloadGrid(option) {
    var defaults = {
        url: "",
        container: "",
        formID: "QueryForm"
    };
    var options = $.extend(defaults, option);
    options.url = GetRandURL(options.url);
    var postJsonData = getPostData(options.formID);
    if ("nodata" == postJsonData) return;
    $("#" + options.container).jqGrid('setGridParam', {
        url: options.url,
        datatype: "json",
        page: 1,
        postData: postJsonData
    }).trigger("reloadGrid");
}

function isNullOrEmpty(v) {
    return v == '' || v == undefined || v == null || typeof (v) == "undefined";
}

Array.prototype.insert = function (index, o) {
    this.splice(index, 0, o);
}

Array.prototype.contains = function (elem) {
    if (this.length == 0) return false;
    for (var i = 0; i < this.length; i++) {
        if (this[i] == elem) return true;
    }
    return false;
}
Array.prototype.indexOf = function (val) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == val) {
            return i;
        }
    }
    return -1;
};
Array.prototype.remove = function (val) {
    var index = this.indexOf(val);
    if (index > -1) {
        this.splice(index, 1);
    }
};
Array.prototype.convertToString = function () {
    var str = "";
    for (var i = 0; i < this.length; i++) {
        str += this[i];
        str += "|";
    }
    return str.length > 0 ? str.substring(0, str.length - 1) : str;
}

//字符串去除空格
String.prototype.Trim = function () {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.LTrim = function () {
    return this.replace(/(^\s*)/g, "");
}
String.prototype.RTrim = function () {
    return this.replace(/(\s*$)/g, "");
}
String.prototype.Decode = function () {
    if (this == null || this == "" || typeof (this) == 'undefined') {
        return this;
    }
    return decodeURIComponent(decodeURIComponent(this));
}

//序列化
Array.prototype.Serialize = function () {
    var str = "";
    str += "[";
    for (var i = 0; i < this.length; i++) {
        str += "{";
        for (var o in this[i]) {
            var v = this[i][o];
            v = isNullOrEmpty(v) ? '\"\"' : v;
            str += "\"" + o + "\":\"" + this[i][o] + "\",";
        }
        if (str.substr(str.length - 1) == ",")
            str = str.substr(0, str.length - 1);
        str += "},";
    }
    if (str.substr(str.length - 1) == ",")
        str = str.substr(0, str.length - 1);
    str += "]";
    return str;
}


Array.prototype.toSpliceString = function () {
    var str = "";
    for (var i = 0; i < this.length; i++) {
        str += this[i] + ",";
    }
    if (str.substr(str.length - 1) == ",")
        str = str.substr(0, str.length - 1);
    return str;
}
var orderBy = function (filedName, reverse, primer) {

    reverse = (reverse) ? -1 : 1;

    return function (a, b) {
        a = a[filedName];
        b = b[filedName];

        if (typeof (primer) != "undefined") {
            a = primer(a);
            b = primer(b);
        }

        if (a < b) {
            return reverse * -1;
        }
        if (a > b) {
            return reverse * 1;
        }
    }
}

//数组排序 顺序
Array.prototype.OrderByAsc = function (filedName, primer) {
    this.sort(orderBy(filedName, false, primer));
    return this;
}


//数组排序 倒序
Array.prototype.OrderByDesc = function (filed, primer) {
    this.sort(orderBy(filedName, true, primer));
    return this;
}



function Export(url, packegeName) {


    $.ajax({
        type: "POST",
        url: url,
        data: {},
        datatype: "json",
        cache: false,
        async: false, //提交表单时锁住浏览器防止页面关闭中断事务
        success: function (data) {
            var Result = eval('(' + data + ')');
            if (Result.Status == 200) {
                window.location.href = '/Server/Export.aspx?action=ExportExcel&filePath=' + Result.Content + '&packegeName=' + packegeName;

                //window.open('/Common/ExportServer.aspx?method=DownLoadFile&filePath=' + Data[0].Content, 'Download');
            }
            else {
                alert(Data[0].Status + ":" + Data[0].Content, function () { });
            }
        },
        error: function (httpRequest, textStatus, errorThrown) {
            var strErrMsg = "意外出错，请刷新页面重试!";
            alert(strErrMsg);
        }
    });




}

function BuildExceptionMessage(data) {
    var Data = eval("[" + data.StateDescription + "]");
    var message = "";
    if (data.Status == 600) {
        message = "消息：<br />";
    };
    for (var i = 0; i < Data.length; i++) {
        for (var item in Data[i]) {
            var key = item;
            var value = Data[i][item];
            message += key + ":";
            message += value;
            message += "<br />";
        }
    }
    return message;
}

function LockWindow(o) {
    if (isNullOrEmpty(o)) return;
    var wo = null;

    if ($.type(o) == "string") {
        wo = $("#" + o);
    }
    if ($.type(o) == "object") {
        wo = o;
    }
    if (0 < wo.length) {
        wo.data('_Dialog_CanClose', false);
    }
}

function UnLockWindow(o) {
    if (isNullOrEmpty(o)) return;
    var wo = null;

    if ($.type(o) == "string") {
        wo = $("#" + o);
    }
    if ($.type(o) == "object") {
        wo = o;
    }
    if (0 < wo.length) {
        wo.data('_Dialog_CanClose', true);
    }
}

function ShowPrompt(o) {
    if (isNullOrEmpty(o)) return;
    var wo = null;

    if ($.type(o) == "string") {
        wo = $("#" + o);
    }
    if ($.type(o) == "object") {
        wo = o;
    }
    if (0 < wo.length) {
        var html = "<div class='post_tipp' style='width:86px;height:6px;float:left;margin:1.2em 0 0.5em 0.4em'><img src=\"/Images/ajaxtipimage.gif\" /></div>";
        $("div.ui-dialog[role='dialog'][aria-describedby='" + wo.attr('id') + "']").find('.ui-dialog-buttonpane').append(html);
    }
}

function HidePrompt(o) {
    if (isNullOrEmpty(o)) return;
    var wo = null;

    if ($.type(o) == "string") {
        wo = $("#" + o);
    }
    if ($.type(o) == "object") {
        wo = o;
    }
    if (0 < wo.length) {
        $("div.ui-dialog[role='dialog'][aria-describedby='" + wo.attr('id') + "']").find('.post_tipp').remove();
    }
}


function NullPageSetup() {
    var hkey_root = 'HKEY_CURRENT_USER';
    var hkey_path = '\\Software\\Microsoft\\Internet Explorer\\PageSetup\\';
    var hkey_key;

    try {
        var RegWsh = new ActiveXObject('WScript.Shell');
        hkey_key = 'header';
        RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, '');
        hkey_key = 'footer';
        RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, '');
        RegWsh.RegWrite(hkey_root + hkey_path + 'margin_top', '0.3');
        RegWsh.RegWrite(hkey_root + hkey_path + 'margin_bottom', '0.3');
        RegWsh.RegWrite(hkey_root + hkey_path + 'margin_left', '0.3');
        RegWsh.RegWrite(hkey_root + hkey_path + 'margin_right', '0.3');
        RegWsh = null;
    }
    catch (e) {
        jqAlert("ActiveX被禁用，请设置为启用");
    }
}

//验证是否包含指定特殊字符
// 实例 var specialChar = ["%", "'", "*", "&", "\\", "\\\\", "+", "<", ">"];
function  CheckSpecialChar(strContent,specialChar)
{
    var len = strContent.length;
    var newContent;
    if(specialChar.length==0)
    {
        return true;
    }
    else{
        for (var i = 0; i < specialChar.length; i++) {
            newContent = strContent.replace(specialChar[i], "");
            if (len != newContent.length) {
                return false;
            }
        }
    }
    return true;
}

//验证内容是否由大小写字母及数字组成
function ValidateContent(strContent) {
    return /(^[A-Za-z0-9]+$)/.test(strContent); 
}

//除去文本中的所有"*"、"＊"、"×"字符
$(function () {
    //alert("tabs");

    $("input[hasfilterstar='false']").keyup(function (e) {
        FilterSym(e);
    });

    $("input[hasFilterStar='false']").change(FilterSym);



})

function FilterSym(e) {
    var Ex = /[\*\＊\×]/g;
    //获取触发事件的对象的值
    var currentValue = e.currentTarget.value;
    var index = currentValue.search(Ex);
    if (index  >= 0) {
        //替换所有"*"、"＊"、"×"字符
        //e.currentTarget.value = currentValue.replace(Ex, "");
        $(e.currentTarget).val(currentValue.replace(Ex, ""))
        e.currentTarget.selectionEnd = index;
        $(e.currentTarget).change();
    }
}